﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace SkynetCE.Foundation.Services.Navigation
{
    public static class NavigationService  
    {
        public static T ResolveService<T>()
        {
            T result = default(T);
            switch (typeof(T).FullName)
            {
                case "SkynetCE.Foundation.Services.DatabaseService.IDatabaseService":
                    result = (T)Activator.CreateInstance(Type.GetType("SkynetCE.Foundation.Services.DatabaseService.DatabaseService, SkynetCE.Foundation"));
                    break;
                case "SkynetCE.Foundation.Services.SkynetService.ISkynetService":
                    result = (T)Activator.CreateInstance(Type.GetType("SkynetCE.Foundation.Services.SkynetService.SkynetService, SkynetCE.Foundation"));
                    break; 

                default:
                    throw new ApplicationException("not implement");                     
            }
            return result;              
        }
        private static T BuildInstance<T>()
        {
            T result = default(T);  
            switch (typeof(T).FullName)
            {
                case "SkynetCE.Administration.Views.MgmCategories.IMgmCategoriesView":
                    result = (T)Activator.CreateInstance(Type.GetType("SkynetCE.Administration.Views.MgmCategories.MgmCategoriesView, SkynetCE.Administration"));                    
                break;
                case "SkynetCE.Administration.Views.MgmExams.IMgmExamView":
                    result = (T)Activator.CreateInstance(Type.GetType("SkynetCE.Administration.Views.MgmExams.MgmExamView, SkynetCE.Administration"));                    
                break;
                case "SkynetCE.Administration.Views.MgmCategoriesMerge.IMgmCategoriesView":
                    result = (T)Activator.CreateInstance(Type.GetType("SkynetCE.Administration.Views.MgmCategoriesMerge.MgmCategoriesMergeView, SkynetCE.Administration"));
                break;
                default:
                    throw new ApplicationException("not implement");
            }
            return result;             
        }
        public static void Navigate<T>(string RegionName, System.Windows.Forms.Form parent)
        {
            var view = BuildInstance<T>();
            switch (RegionName)
            {
                case Foundation.Constants.RegionNames.ModalRegion:
                    var target = view as Form;
                    target.Owner = parent; 
                    target.Show(); 
                    break;
                default:
                    break;
            }
        }        
    }
}
